package com.oa.controller.admin;

import com.oa.pojo.Department;
import com.oa.service.admin.AdminService;
import com.oa.service.admin.DeptManagerService;
import com.oa.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 一拳超人
 * @Date: 2021/10/18 19:22
 */
@CrossOrigin
@RestController
@RequestMapping("/admin/dept")
public class DeptManagerController {
    @Autowired
    private DeptManagerService deptManagerService;

    @Autowired
    private AdminService adminService;

    @GetMapping("/getDeptList/{level}")
    public SysResult getDeptList(@PathVariable Integer level) {
        return SysResult.success(adminService.getDepartmentInfo(level));
    }

    @GetMapping("/getDeptInfo/{id}")
    public SysResult getDeptInfo(@PathVariable Integer id) {
        return SysResult.success(deptManagerService.getDeptManager(id));
    }

    @GetMapping("/getEmpList")
    public SysResult getEmpList() {
        return SysResult.success(deptManagerService.getEmpList());
    }

    @PutMapping("/updateDeptInfo")
    public SysResult updateDeptInfo(@RequestBody Department department) {
        return SysResult.success(deptManagerService.updateDeptInfo(department));
    }

    @PostMapping("/addNewDept")
    public SysResult addNewDept(@RequestBody Department department) {
        return deptManagerService.addNewDept(department);
    }

    @DeleteMapping("/deleteDept/{depId}")
    public SysResult deleteDept(@PathVariable Integer depId) {
        return deptManagerService.deleteDept(depId);
    }
}
